<template>
	<view class="flex-col page">
		<view>
			<view :style="{height:statusBarHeight+'px'}"></view>
			<u-navbar title="我的评价" bgColor="#F5F5F5" @leftClick="$nav(2)">	
			</u-navbar>
		</view>
		
		
		<view v-if="list.length > 0">
			<view class="flex-col com-content" v-for="(item,index) in list" :key="index">
				<view class="flex-row justify-between">
					<u-rate active-color="#5c8edc" inactive-color="#b2b2b2" :value="item.star" readonly gutter="3"></u-rate>	
					<view @click="deleteComment(item)" style="font-size: 28rpx;color: #999;margin-right: 10rpx;">删除</view>
				</view>
				
				<view style="margin-top: 30rpx;margin-left: 5rpx;">{{item.comment}}</view>	
				<view v-if="item.img_url">
					<image class='img_wrap_one' :src="item.img_url" @click="clickImg(item.img_url)"  style="margin-top: 15rpx;border-radius: 5rpx;"/>
				</view>
				<view v-else></view>
					
					
				<view class="goods_bg" @click="goGoods(item)">
					<view>{{item.name}}</view>
					<image class='img_wrap_one' :src="item.goods_img" @click="clickImg(item.goods_img)"  style="margin-top: 15rpx;border-radius: 5rpx;"/>
				</view>	
				
				<view style="color: #555;font-size: 26rpx;margin-top: 20rpx;">{{item.create_date}}</view>
			</view>
		</view>
		<view v-else class="flex-col items-center" style="margin-top: 80rpx;">
			<image src="/static/data_empty.png"></image>
			<text style="color: #c0c4cc;">暂无数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				page:1,
				status: 'loadmore',
				loadText: {
					loadmore: '下拉加载更多...',
					loading: '加载中...',
					nomore: '没有更多数据了...'
				},
			};
		},
		onLoad() {
			
		},
		onShow() {
			this.list = [];
			this.page = 1;
			this.getCommentList();
		},
		onPullDownRefresh() {
			this.list = [];
			this.page = 1;
			this.getCommentList();
		},
		onReachBottom() {
			this.getCommentList();
		},
		computed:{
			statusBarHeight(){
				return this.$store.state.statusBarHeight + 44
			}
		},
		methods:{
			deleteComment(item){
				let that = this;
				uni.showModal({
					title:  '提示',
					content: '确认删除该评价吗？',
					cancelText: '取消',
					confirmText: '确定',
					confirmColor: '#007aff',
					success(res) {
						if (res.confirm) {
							that.toDelete(item);
						}
					}
				})
			},
			toDelete(item){
				this.$request({
					url:'?c=Order&a=orderDeleReviews',
					type:'post',
					data:{
					  id: item.id
					}
				}).then(res =>{
					uni.showToast({
						title:'成功'
					})
					this.list = [];
					this.page = 1;
					this.getCommentList();
				})
			},
			getCommentList(){
				this.$request({
					url:'?c=Order&a=commentList',
					type:'post',
					data:{
						page: this.page,
						limit: 20
					}
				}).then(res =>{
					uni.stopPullDownRefresh();
					this.status = 'loadmore';
					if (res.data && res.data.length > 0) {
						this.list = [...this.list, ...res.data];
						this.page += 1;
						if (res.data.length < 10) {
							this.status = 'nomore';
						}
					} else {
						this.status = 'nomore';
					}
				});
			},
			clickImg(url){
				uni.previewImage({
					urls:[url]
				});
			},
			goGoods(item){
				uni.navigateTo({
					url: '/pages/product/index?goods_id='+item.goods_id + '&goodsType=0'
				});
			},
			staticResource(path){
				return "https://ysmz.scmzhc.com/static/mini/images/"+path;
			}
		}
	}
</script>

<style lang="scss">
.page{
	width: 100%;
	overflow-y: auto;
	overflow-x: hidden;
	height: 100%;
	background-color: #F5F5F5;
}
.img_wrap_one {
	height: 230rpx;
	width: 190rpx;
}
.com-content{
	background-color: #fff;
	margin: 20rpx;
	border-radius: 10rpx;
	padding: 20rpx;
}
.goods_bg{
	background-color: #F5F5F5;
	width: 100%;
	display: flex;
	flex-direction: column;
	margin-top: 30rpx;
	padding: 20rpx;
	border-radius: 8rpx;
}
</style>
